package com.spider.test03;

public class Demo1 {
    public static void main(String[] args) {
        //正则表达式练习
        //	(1)验证用户输入的是否是数字？
        String regex = "\\d+";
        String str = "123";
        boolean b = str.matches(regex);
        System.out.println(b);
        System.out.println("--------------------------------");
        //	(2)验证用户输入的是否是合法的IP地址？
        String regex1 = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
        String str1 = "192.168.1.1";
        boolean b1 = str1.matches(regex1);
        System.out.println(b1);
        System.out.println("--------------------------------");
        //	(3)验证用户输入的是否是合法的URL网址？
        String regex2 = "http://[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+";
        String str2 = "http://www.baidu.com";
        boolean b2 = str2.matches(regex2);
        System.out.println(b2);
        System.out.println("--------------------------------");
    }
}
